
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class Geo_LocationComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public Geo_LocationComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public Geo_Location SelectOne(int GeoLocationID)
        {  
			PlacementManager.DAL.Geo_Location_DAL o = new PlacementManager.DAL.Geo_Location_DAL();
			o.GeoLocationID = GeoLocationID;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.Geo_Location Geo_LocationToReturn = new PlacementManager.Geo_Location((int)row["GeoLocationID"], (int)row["UniqueFeatureID"], (int)row["UniqueNameID"], (double)row["Latitude"], (double)row["Longitude"], (int)row["DMS_Latitude"], (int)row["DMS_Longitude"], (string)row["UniversalTransverseMercator"], (string)row["JointOperationsGraphic"], (string)row["FeatureClassification"], (string)row["FeatureDesignation"], (string)row["CountryCode"], (int)row["CountryID"], (string)row["AdministrativeDivision"], (int)row["AdministrativeDivisionID"], (string)row["ShortName"], (string)row["SortName"], (string)row["FullName"], (DateTime)row["DateCreated"]);
				return Geo_LocationToReturn;
			}
			else
			{
				PlacementManager.Geo_Location Geo_LocationToReturnEmpty = new PlacementManager.Geo_Location();
                return Geo_LocationToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<Geo_Location> SelectAll(string sortExpression)
        {
            List<Geo_Location> listGeo_Location = new List<Geo_Location>();
            PlacementManager.DAL.Geo_Location_DAL o = new PlacementManager.DAL.Geo_Location_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listGeo_Location.Add(new Geo_Location((int)row["GeoLocationID"], (int)row["UniqueFeatureID"], (int)row["UniqueNameID"], (double)row["Latitude"], (double)row["Longitude"], (int)row["DMS_Latitude"], (int)row["DMS_Longitude"], (string)row["UniversalTransverseMercator"], (string)row["JointOperationsGraphic"], (string)row["FeatureClassification"], (string)row["FeatureDesignation"], (string)row["CountryCode"], (int)row["CountryID"], (string)row["AdministrativeDivision"], (int)row["AdministrativeDivisionID"], (string)row["ShortName"], (string)row["SortName"], (string)row["FullName"], (DateTime)row["DateCreated"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listGeo_Location.Sort(new Geo_LocationComparer(sortExpression));
            return listGeo_Location;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<Geo_Location> SelectAllWAdministrativeDivisionID(int AdministrativeDivisionID, string sortExpression)
		{
			List<Geo_Location> listGeo_Location = new List<Geo_Location>();
			PlacementManager.DAL.Geo_Location_DAL o = new PlacementManager.DAL.Geo_Location_DAL();
			o.AdministrativeDivisionID = AdministrativeDivisionID;
			DataSet ds = o.SelectAllWAdministrativeDivisionID();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listGeo_Location.Add(new Geo_Location((int)row["GeoLocationID"], (int)row["UniqueFeatureID"], (int)row["UniqueNameID"], (double)row["Latitude"], (double)row["Longitude"], (int)row["DMS_Latitude"], (int)row["DMS_Longitude"], (string)row["UniversalTransverseMercator"], (string)row["JointOperationsGraphic"], (string)row["FeatureClassification"], (string)row["FeatureDesignation"], (string)row["CountryCode"], (int)row["CountryID"], (string)row["AdministrativeDivision"], (int)row["AdministrativeDivisionID"], (string)row["ShortName"], (string)row["SortName"], (string)row["FullName"], (DateTime)row["DateCreated"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listGeo_Location.Sort(new Geo_LocationComparer(sortExpression));
			return listGeo_Location;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(Geo_Location o)
        {	
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location = new PlacementManager.DAL.Geo_Location_DAL();
			oGeo_Location.UniqueFeatureID = o.UniqueFeatureID;
			oGeo_Location.UniqueNameID = o.UniqueNameID;
			oGeo_Location.Latitude = o.Latitude;
			oGeo_Location.Longitude = o.Longitude;
			oGeo_Location.DMS_Latitude = o.DMS_Latitude;
			oGeo_Location.DMS_Longitude = o.DMS_Longitude;
			oGeo_Location.UniversalTransverseMercator = o.UniversalTransverseMercator;
			oGeo_Location.JointOperationsGraphic = o.JointOperationsGraphic;
			oGeo_Location.FeatureClassification = o.FeatureClassification;
			oGeo_Location.FeatureDesignation = o.FeatureDesignation;
			oGeo_Location.CountryCode = o.CountryCode;
			oGeo_Location.CountryID = o.CountryID;
			oGeo_Location.AdministrativeDivision = o.AdministrativeDivision;
			oGeo_Location.AdministrativeDivisionID = o.AdministrativeDivisionID;
			oGeo_Location.ShortName = o.ShortName;
			oGeo_Location.SortName = o.SortName;
			oGeo_Location.FullName = o.FullName;
			oGeo_Location.DateCreated = o.DateCreated;

            return oGeo_Location.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(int UniqueFeatureID, int UniqueNameID, double Latitude, double Longitude, int DMS_Latitude, int DMS_Longitude, string UniversalTransverseMercator, string JointOperationsGraphic, string FeatureClassification, string FeatureDesignation, string CountryCode, int CountryID, string AdministrativeDivision, int AdministrativeDivisionID, string ShortName, string SortName, string FullName, DateTime DateCreated)
        {
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location = new PlacementManager.DAL.Geo_Location_DAL();

			oGeo_Location.UniqueFeatureID = UniqueFeatureID;
			oGeo_Location.UniqueNameID = UniqueNameID;
			oGeo_Location.Latitude = Latitude;
			oGeo_Location.Longitude = Longitude;
			oGeo_Location.DMS_Latitude = DMS_Latitude;
			oGeo_Location.DMS_Longitude = DMS_Longitude;
			oGeo_Location.UniversalTransverseMercator = UniversalTransverseMercator;
			oGeo_Location.JointOperationsGraphic = JointOperationsGraphic;
			oGeo_Location.FeatureClassification = FeatureClassification;
			oGeo_Location.FeatureDesignation = FeatureDesignation;
			oGeo_Location.CountryCode = CountryCode;
			oGeo_Location.CountryID = CountryID;
			oGeo_Location.AdministrativeDivision = AdministrativeDivision;
			oGeo_Location.AdministrativeDivisionID = AdministrativeDivisionID;
			oGeo_Location.ShortName = ShortName;
			oGeo_Location.SortName = SortName;
			oGeo_Location.FullName = FullName;
			oGeo_Location.DateCreated = DateCreated;

            return oGeo_Location.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(Geo_Location o)
        {	
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location = new PlacementManager.DAL.Geo_Location_DAL();
			oGeo_Location.GeoLocationID = o.GeoLocationID;
			oGeo_Location.UniqueFeatureID = o.UniqueFeatureID;
			oGeo_Location.UniqueNameID = o.UniqueNameID;
			oGeo_Location.Latitude = o.Latitude;
			oGeo_Location.Longitude = o.Longitude;
			oGeo_Location.DMS_Latitude = o.DMS_Latitude;
			oGeo_Location.DMS_Longitude = o.DMS_Longitude;
			oGeo_Location.UniversalTransverseMercator = o.UniversalTransverseMercator;
			oGeo_Location.JointOperationsGraphic = o.JointOperationsGraphic;
			oGeo_Location.FeatureClassification = o.FeatureClassification;
			oGeo_Location.FeatureDesignation = o.FeatureDesignation;
			oGeo_Location.CountryCode = o.CountryCode;
			oGeo_Location.CountryID = o.CountryID;
			oGeo_Location.AdministrativeDivision = o.AdministrativeDivision;
			oGeo_Location.AdministrativeDivisionID = o.AdministrativeDivisionID;
			oGeo_Location.ShortName = o.ShortName;
			oGeo_Location.SortName = o.SortName;
			oGeo_Location.FullName = o.FullName;
			oGeo_Location.DateCreated = o.DateCreated;

            return oGeo_Location.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int GeoLocationID, int UniqueFeatureID, int UniqueNameID, double Latitude, double Longitude, int DMS_Latitude, int DMS_Longitude, string UniversalTransverseMercator, string JointOperationsGraphic, string FeatureClassification, string FeatureDesignation, string CountryCode, int CountryID, string AdministrativeDivision, int AdministrativeDivisionID, string ShortName, string SortName, string FullName, DateTime DateCreated)
        {
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location = new PlacementManager.DAL.Geo_Location_DAL();

			oGeo_Location.GeoLocationID = GeoLocationID;
			oGeo_Location.UniqueFeatureID = UniqueFeatureID;
			oGeo_Location.UniqueNameID = UniqueNameID;
			oGeo_Location.Latitude = Latitude;
			oGeo_Location.Longitude = Longitude;
			oGeo_Location.DMS_Latitude = DMS_Latitude;
			oGeo_Location.DMS_Longitude = DMS_Longitude;
			oGeo_Location.UniversalTransverseMercator = UniversalTransverseMercator;
			oGeo_Location.JointOperationsGraphic = JointOperationsGraphic;
			oGeo_Location.FeatureClassification = FeatureClassification;
			oGeo_Location.FeatureDesignation = FeatureDesignation;
			oGeo_Location.CountryCode = CountryCode;
			oGeo_Location.CountryID = CountryID;
			oGeo_Location.AdministrativeDivision = AdministrativeDivision;
			oGeo_Location.AdministrativeDivisionID = AdministrativeDivisionID;
			oGeo_Location.ShortName = ShortName;
			oGeo_Location.SortName = SortName;
			oGeo_Location.FullName = FullName;
			oGeo_Location.DateCreated = DateCreated;

            return oGeo_Location.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(Geo_Location o)
        {
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location_DAL = new PlacementManager.DAL.Geo_Location_DAL();
            oGeo_Location_DAL.GeoLocationID = o.GeoLocationID;
            return oGeo_Location_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int GeoLocationID)
        {
            PlacementManager.DAL.Geo_Location_DAL oGeo_Location_DAL = new PlacementManager.DAL.Geo_Location_DAL();
            oGeo_Location_DAL.GeoLocationID = GeoLocationID;
            return oGeo_Location_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWAdministrativeDivisionID(int AdministrativeDivisionID)
		{
			PlacementManager.DAL.Geo_Location_DAL oGeo_Location_DAL = new PlacementManager.DAL.Geo_Location_DAL();
			oGeo_Location_DAL.AdministrativeDivisionID = AdministrativeDivisionID;			
			return oGeo_Location_DAL.DeleteAllWAdministrativeDivisionID();
		}

	}
	
	public class Geo_LocationComparer : IComparer<Geo_Location>
    {
        private string _sortColumn;
        private bool _reverse;

        public Geo_LocationComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(Geo_Location a, Geo_Location b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "GeoLocationID":
					retVal = String.Compare(a.GeoLocationID.ToString(), b.GeoLocationID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UniqueFeatureID":
					retVal = String.Compare(a.UniqueFeatureID.ToString(), b.UniqueFeatureID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UniqueNameID":
					retVal = String.Compare(a.UniqueNameID.ToString(), b.UniqueNameID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Latitude":
					retVal = String.Compare(a.Latitude.ToString(), b.Latitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Longitude":
					retVal = String.Compare(a.Longitude.ToString(), b.Longitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DMS_Latitude":
					retVal = String.Compare(a.DMS_Latitude.ToString(), b.DMS_Latitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DMS_Longitude":
					retVal = String.Compare(a.DMS_Longitude.ToString(), b.DMS_Longitude.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UniversalTransverseMercator":
					retVal = String.Compare(a.UniversalTransverseMercator.ToString(), b.UniversalTransverseMercator.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "JointOperationsGraphic":
					retVal = String.Compare(a.JointOperationsGraphic.ToString(), b.JointOperationsGraphic.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FeatureClassification":
					retVal = String.Compare(a.FeatureClassification.ToString(), b.FeatureClassification.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FeatureDesignation":
					retVal = String.Compare(a.FeatureDesignation.ToString(), b.FeatureDesignation.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CountryCode":
					retVal = String.Compare(a.CountryCode.ToString(), b.CountryCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CountryID":
					retVal = String.Compare(a.CountryID.ToString(), b.CountryID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AdministrativeDivision":
					retVal = String.Compare(a.AdministrativeDivision.ToString(), b.AdministrativeDivision.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AdministrativeDivisionID":
					retVal = String.Compare(a.AdministrativeDivisionID.ToString(), b.AdministrativeDivisionID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "ShortName":
					retVal = String.Compare(a.ShortName.ToString(), b.ShortName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "SortName":
					retVal = String.Compare(a.SortName.ToString(), b.SortName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FullName":
					retVal = String.Compare(a.FullName.ToString(), b.FullName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
